package top.aoyudi.utils;

import java.sql.*;

public class MysqlUtil {
    // 数据库连接
    public static Statement mySqlConnect(String url, String userName, String passWord)  {
        try {
            //1.加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //2.连接成功，数据库对象 Connection
            Connection connection = DriverManager.getConnection(url, userName, passWord);
            //3.返回执行SQL对象Statement
            return connection.createStatement();
        } catch (ClassNotFoundException e) {
            System.out.println("未找到数据库连接驱动-com.mysql.cj.jdbc.Driver");
        } catch (SQLException e) {
            System.out.println("运行时出现异常");
            throw new RuntimeException(e);
        }
        return null;
    }

}